var thissave,vdata1,vehsingle;
var SavecProxy = Objs("model.InfoProxy",
	Proxy,
{
	initialize: function( name,lists)
	{
		InfoProxy.$super.initialize.call( this, name,lists);
        thissave=this;
	},
	shareVehicle:function()
	{
		var sharebyemailobject=new Object();
		sharebyemailobject.vehicle_id=idlas;
		sharebyemailobject.admin_id=adminid;
		
		if ($(jQuery("#cardetcheck")).attr('checked')) 
		{
		sharebyemailobject.is_car_details=1;
		}
	    else
		{
			sharebyemailobject.is_car_details=0;
		}
		if ($(jQuery("#sellerdetcheck")).attr('checked')) 
		{
		sharebyemailobject.is_seller_details=1;
		}
		else
		{
		sharebyemailobject.is_seller_details=0;
		}
			if ($(jQuery("#privatnotcheck")).attr('checked')) 
		{
		sharebyemailobject.is_private_details=1;
		}
		else
		{
		sharebyemailobject.is_private_details=0;
		}
			if ($(jQuery("#towdetcheck")).attr('checked')) 
		{
		sharebyemailobject.is_tow_details=1;
		}
		else
		{
		sharebyemailobject.is_tow_details=0;
		}
			if ($(jQuery("#mapcheck")).attr('checked')) 
		{
		sharebyemailobject.is_map_details=1;
		}
		else
		{
		sharebyemailobject.is_map_details=0;
		}
		
		sharebyemailobject.note=document.getElementById("anynote").value;
		if ($(jQuery("#useanother")).attr('checked')) {
		sharebyemailobject.send_to=document.getElementById("anoemail").value;
		$.mobile.showPageLoadingMsg();
		$.ajax({
			type: "POST",
			url:"../services/JqueryVehicleService.php?action=SharebyUnknownEmail",
			data:sharebyemailobject,
			success: function(data,status) {
					$.mobile.hidePageLoadingMsg();
			if(data)
			{
			alert(data);
			}
			else
			{
				alert("Vehicle Shared Successfully");
			}
		
			}
			});
		}
		else
		{
		if(document.getElementById("to").value=="Choose one")
		{
		alert("select a partner ");
		}
		else
		{ 
		sharebyemailobject.partner_id=partnerid;
		sharebyemailobject.user_type=usertype;
		sharebyemailobject.send_to=document.getElementById("to").value;
		$.mobile.showPageLoadingMsg();
		$.ajax({
			type: "POST",
			url:"../services/JqueryVehicleService.php?action=SharebyEmail",
			data:sharebyemailobject,
			success: function(data,status) {
					$.mobile.hidePageLoadingMsg();
			//var sharealert= eval('(' + data + ')');
			if(data)
			{
			alert(data);
			}
			else
			{
				alert("Vehicle Shared Successfully");
			}
		
			}
			});
	      }
	     }
	
	},
	getPartnerlist:function()
	{
	$.mobile.showPageLoadingMsg();
	$.ajax({
		type: "POST",
		url:"../services/JqueryVehicleService.php?action=getPartner",
		success: function(data,status) {
		var partner= eval('(' + data + ')');
		thissave.sendNotification( NotificationNames.PARTNERLIST, partner );
		$.mobile.hidePageLoadingMsg();
		}
	});
	},
	addNewvehicle:function()
	{ 
	$.mobile.showPageLoadingMsg();
	booleansavedet=0;
	 var vehicledata=new Object();
	 vehicledata.firstname=fadminname;
	 vehicledata.adminid=adminid;
	vehicledata.year=Number(document.getElementById("addnewyear").value);
    vehicledata.make=document.getElementById("addnewmake").value;
	vehicledata.model=document.getElementById("addnewmodel").value;
	if(document.getElementById("addnewtransmission").value=="Choose one")
    {
     vehicledata.transmission='';
    }
    else
    {
    vehicledata.transmission=document.getElementById("addnewtransmission").value;
    }
	
	vehicledata.asking_price=askkprice;
	
	 vehicledata.first_name=document.getElementById("addnewname").value;
    if(document.getElementById("addnewpriphone").value.length==12)
	{
	var pri=document.getElementById("addnewpriphone").value;
     var str=pri.split("-");
    vehicledata.phone=str[0]+str[1]+str[2];	
	}
	else
	{
	    vehicledata.phone=document.getElementById("addnewpriphone").value;
	}
    vehicledata.email=document.getElementById("addnewemail").value;
    vehicledata.street_address=document.getElementById("addnewaddress").value;
    vehicledata.city=document.getElementById("addnewcity").value;
    if(document.getElementById("addnewstate").value=="Choose one")
    {
    vehicledata.state='';
    }
    else
    {
    vehicledata.state=document.getElementById("addnewstate").value;
    }
 $.ajax({
		type: "POST",
		url:"../services/JqueryAddNewVehicle.php?action=create&submit_type=0",
		data:vehicledata,
		success: function(data,status) {
		vsingledata= eval('(' + data + ')');
		
			vehsingle.is_read=vsingledata.vsingle.vehicle[0].is_read;
	
			vehsingle.is_watch=vsingledata.vsingle.vehicle[0].is_watch;
		   vehsingle.vehicle_id=vsingledata.vsingle.vehicle[0].vehicle_id;
		   idlas=vehsingle.vehicle_id;
		   vehsingle.year=vsingledata.vsingle.vehicle[0].year;
           vehsingle.make=vsingledata.vsingle.vehicle[0].make;
	       vehsingle.model=vsingledata.vsingle.vehicle[0].model;
		   vehsingle.mileage=vsingledata.vsingle.vehicle[0].mileage;
           vehsingle.wrong=vsingledata.vsingle.vehicle[0].wrong;
	       vehsingle.great=vsingledata.vsingle.vehicle[0].great;
		   vehsingle.paper_work=vsingledata.vsingle.vehicle[0].paper_work;
		   vehsingle.title_name=vsingledata.vsingle.vehicle[0].title_name;
	       vehsingle.title_note=vsingledata.vsingle.vehicle[0].title_note;
		   vehsingle.ad_source=vsingledata.vsingle.vehicle[0].ad_source;
		   vehsingle.vin=vsingledata.vsingle.vehicle[0].vin;
		   vehsingle.drivetrain_type=vsingledata.vsingle.vehicle[0].drivetrain_type;
		   vehsingle.engine=vsingledata.vsingle.vehicle[0].engine;
		   vehsingle.transmission=vsingledata.vsingle.vehicle[0].transmission;
	       //vehsingle.private_note=vsingledata.vsingle.vehicle[0].private_note;
		    /*contactinfo*/
		   vehsingle.first_name=vsingledata.vsingle.vehicle[0].first_name;
		   vehsingle.bussiness_name=vsingledata.vsingle.vehicle[0].bussiness_name;
           vehsingle.contact_name=vsingledata.vsingle.vehicle[0].contact_name;
	       vehsingle.street_address=vsingledata.vsingle.vehicle[0].street_address;
		   vehsingle.city=vsingledata.vsingle.vehicle[0].city;
           vehsingle.state=vsingledata.vsingle.vehicle[0].state;
	       vehsingle.zip=vsingledata.vsingle.vehicle[0].zip;
		   vehsingle.phone=vsingledata.vsingle.vehicle[0].phone;
		   vehsingle.cell_phone=vsingledata.vsingle.vehicle[0].cell_phone;
		   vehsingle.email=vsingledata.vsingle.vehicle[0].email;
	       vehsingle.contact_me=vsingledata.vsingle.vehicle[0].contact_me;
		   vehsingle.contact_note=vsingledata.vsingle.vehicle[0].contact_note;
           vehsingle.delivery=vsingledata.vsingle.vehicle[0].delivery;
	       vehsingle.date=vsingledata.vsingle.vehicle[0].date;
		   vehsingle.color=vsingledata.vsingle.vehicle[0].color;
		   vehsingle.delivery_note=vsingledata.vsingle.vehicle[0].delivery_note;
		   /*Comments*/
		   vehsingle.messages=[];
		   vehsingle.private_notes=[];
		   vehsingle.images=[];
		   vehsingle.reminders=[];
		   var messarray=new Array();
		   for(i=0;i<vsingledata.vsingle.vehicle[0].messages.length;i++)
          {  
		   vehsingle.messages.push(vsingledata.vsingle.vehicle[0].messages[i]);
		  }
		  
		   /*Pnotes*/
		   var pnotes=new Array();
		   for(i=0;i<vsingledata.vsingle.vehicle[0].pnotes.length;i++)
          {  
		   vehsingle.private_notes.push(vsingledata.vsingle.vehicle[0].pnotes[i]);
		  }
		  /*Images*/
		   for(i=0;i<vsingledata.vsingle.vehicle[0].images.length;i++)
          {  
		   vehsingle.images.push(vsingledata.vsingle.vehicle[0].images[i]);
		  }
		  
		    for(i=0;i<vsingledata.vsingle.vehicle[0].reminder_1.length;i++)
          {  //alert(vsingledata.vsingle.vehicle[0].reminder_1[i].watchid);
		   vehsingle.reminders.push(vsingledata.vsingle.vehicle[0].reminder_1[i]);
		  }
		   /*Price*/
		    vehsingle.asking_price=vsingledata.vsingle.vehicle[0].asking_price;
	        vehsingle.bid_price=vsingledata.vsingle.vehicle[0].bid_price;
		    vehsingle.accepted_price=vsingledata.vsingle.vehicle[0].accepted_price;
		  /*Vlocation*/
		   vehsingle.v_street_address=vsingledata.vsingle.vehicle[0].v_street_address;
	       vehsingle.v_city=vsingledata.vsingle.vehicle[0].v_city;
		   vehsingle.v_state=vsingledata.vsingle.vehicle[0].v_state;
		   vehsingle.v_zip=vsingledata.vsingle.vehicle[0].v_zip;
		   vehsingle.located_at=vsingledata.vsingle.vehicle[0].located_at;
		   vehsingle.i_want_to=vsingledata.vsingle.vehicle[0].i_want_to;
		   thissave.sendNotification( NotificationNames.GETSIN, 'gets' );	
	    
		$.mobile.hidePageLoadingMsg();
		}
		});
	},
	updateWatchlist:function()
	{
	var remobject=new Object();
	remobject.vehicle_id=idlas;
	remobject.to_date=document.getElementById("remremove").value;
	remobject.remind_note=document.getElementById("remnote").value;
	remobject.isWatch=1;
	remobject.remind_by=fadminname;
	remobject.set_by=adminid;
	remobject.isReminder=1;
	  $.ajax({
		type: "POST",
		url:"../services/JqueryVehicleservice.php?action=updateWatchList",
		data:remobject,
		success: function(data,status) {
		length=1;
		todate=document.getElementById("remremove").value;
		alert("Sucess");
	//	document.getElementById("remremove").value=remobject.remind_note;
		thissave.sendNotification( NotificationNames.SAVEREM, 'li' );	
		}
		});
	},
	saveWatchlist:function()
	{ 
	var remobject=new Object();
	remobject.vehicle_id=idlas;
	if ($(jQuery("#checkbox-1")).attr('checked')) 
	{
	remobject.to_date=document.getElementById("remremove").value;
	remobject.remind_note=document.getElementById("remnote").value;
	remobject.isReminder=1;
	}
	else
	{
	remobject.to_date='';
	remobject.remind_note='';
	remobject.isReminder=0;
	}
	
	remobject.isWatch=1;
	remobject.remind_by=fadminname;
	remobject.set_by=adminid;
	
	  $.ajax({
		type: "POST",
		url:"../services/JqueryVehicleservice.php?action=setWatchList",
		data:remobject,
		success: function(data,status) {
		length=1;
		todate=document.getElementById("remremove").value;
		alert("Sucess");
	//	document.getElementById("remremove").value=remobject.remind_note;
		thissave.sendNotification( NotificationNames.SAVEREM, 'li' );	
		}
		});
	},
	Unlock:function()
	{ 
	
	var idlast=new Object();
	idlast.vehicle_id=idlas;
	//alert(idlast.vehicle_id);
	  $.ajax({
		type: "POST",
		url:"../services/JqueryVehicleservice.php?action=unlock",
		data:idlast
		});
	},
	getCount:function()
	{
	$.mobile.showPageLoadingMsg();
      $.ajax({
		type: "POST",
		url:"../services/JqueryVehicleservice.php?action=getcount",
		success: function(data,status) {
			 var data= eval('(' + data + ')');
		document.getElementById("nscount").innerHTML=data.countnum[0];
			document.getElementById("bacount").innerHTML=data.countnum[1];
			document.getElementById("allcount").innerHTML=data.countnum[2];
		 thissave.sendNotification( NotificationNames.LISTC, 'li' );	
	   		$.mobile.hidePageLoadingMsg();
		}
		});
	},
	addcomment:function(mess)
	{ 
	 
	  $.mobile.showPageLoadingMsg();
      $.ajax({
		type: "POST",
		url:"../services/JqueryVehicleservice.php?action=addMessages",
		data:mess,
	    success: function(data,status) {
		var mdata= eval('(' + data + ')');
		 thissave.sendNotification( NotificationNames.GETMESS, mdata );	
		$.mobile.hidePageLoadingMsg();
		}
		});
	},
	addpnotes:function(mess)
	{ 
	  $.mobile.showPageLoadingMsg();
      $.ajax({
		type: "POST",
		url:"../services/JqueryVehicleservice.php?action=addPnotes",
		data:mess,
	    success: function(data,status) {
		
		 thissave.sendNotification( NotificationNames.GETPNOTES, 'vcv' );	
		$.mobile.hidePageLoadingMsg();
		}
		});
	},
	savevdet:function(VehdetVO,datas)
	{  // alert(fadminname);
	vdata1=new Object();
	vdata1.isNormal=datas;
	this.changeObject(VehdetVO);
	$.mobile.showPageLoadingMsg();
	
	 $.ajax({
		type: "POST",
		url:"../services/JqueryVehicleservice.php?action=update",
		data:vdata1,
		 success: function(data,status) {
		 
		 var data= eval('(' + data + ')');
		
		 thissave.sendNotification( NotificationNames.GETSAVE, data );
	   		$.mobile.hidePageLoadingMsg();
			}

		});
		//alert("FD");
	
	},
	changeObject:function(VehdetVO)
	{   vdata1.fadminname=fadminname;
	//alert(adminid);
	  vdata1.admin_id=adminid;
	     vdata1.is_read= VehdetVO.is_read;
		 vdata1.is_watch= VehdetVO.is_watch;
		  vdata1.vehicle_id=VehdetVO.vehicle_id;
		  vdata1.year= VehdetVO.year;
           vdata1.make=VehdetVO.make;
	       vdata1.model=VehdetVO.model;
		  vdata1.mileage= VehdetVO.mileage;
           vdata1.wrong=VehdetVO.wrong;
	       vdata1.great=VehdetVO.great;
		   vdata1.paper_work=VehdetVO.paper_work;
		   vdata1.title_name=VehdetVO.title_name;
	       vdata1.title_note=VehdetVO.title_note;
		   vdata1.ad_source=VehdetVO.ad_source;
		   vdata1.vin=VehdetVO.vin;
		   vdata1.drivetrain_type=VehdetVO.drivetrain_type;
		  vdata1.engine= VehdetVO.engine;
		  vdata1.transmission= VehdetVO.transmission;
		    /*contactinfo*/
		   vdata1.first_name=VehdetVO.first_name;
		   vdata1.bussiness_name=VehdetVO.bussiness_name;
           vdata1.contact_name=VehdetVO.contact_name;
	      vdata1.street_address= VehdetVO.street_address;
		  vdata1.city= VehdetVO.city;
          vdata1.state= VehdetVO.state;
	      vdata1.zip= VehdetVO.zip;
		  vdata1.phone= VehdetVO.phone;
		  vdata1.cell_phone= VehdetVO.cell_phone;
		   vdata1.email=VehdetVO.email;
	       vdata1.contact_me=VehdetVO.contact_me;
		   vdata1.contact_note=VehdetVO.contact_note;
           vdata1.delivery=VehdetVO.delivery;
	      vdata1.date= VehdetVO.date;
		  vdata1.color= VehdetVO.color;
		  vdata1.delivery_note= VehdetVO.delivery_note;
		  vdata1.asking_price=  VehdetVO.asking_price;
	      vdata1.bid_price=  VehdetVO.bid_price;
		  vdata1.accepted_price=  VehdetVO.accepted_price;
		  /*Vlocation*/
		  vdata1.v_street_address= VehdetVO.v_street_address;
	      vdata1.v_city= VehdetVO.v_city;
		  vdata1.v_state= VehdetVO.v_state;
		  vdata1.v_zip= VehdetVO.v_zip;
		  vdata1.located_at= VehdetVO.located_at;
		  vdata1.i_want_to= VehdetVO.i_want_to;
	}

});
 